<template>
  <div class="card content-box">
    <div class="table-box">
      <ProTable ref="proTable" :columns="columns" :request-api="getTableList">
        <!-- 表格 header 按钮 -->
        <template #tableHeader>
          <el-button v-auth="'job:log:export'" type="primary" :icon="Download" plain @click="exportExcel">导出</el-button>
        </template>
        <!--        &lt;!&ndash; 菜单操作 &ndash;&gt;-->
        <!--        <template #operation="scope">-->
        <!--        </template>-->
      </ProTable>
    </div>
  </div>
</template>

<script setup lang="ts">
import ProTable from "@/components/ProTable/index.vue";
import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
import { exportJobLogExcel, getJobLogPage } from "@/api/modules/job/JobLog";
import { ref } from "vue";
import { getDictItem } from "@/api/modules/sys/dict";
import { Download } from "@element-plus/icons-vue";
import { useDownload } from "@/hooks/useDownload";

// 表格配置项
const columns: ColumnProps[] = [
  // { type: "selection", fixed: "left", width: 70 },
  {
    prop: "jobId",
    label: "定时任务id",
    search: { el: "input", tooltip: "定时任务id" }
  },
  {
    prop: "beanName",
    label: "执行bean的名称",
    search: { el: "input", tooltip: "执行bean的名称" }
  },
  {
    prop: "params",
    label: "执行参数"
  },
  {
    prop: "succeed",
    label: "是否成功",
    tag: true,
    enum: () => getDictItem("yesOrNo"),
    search: { el: "select-v2", tooltip: "是否成功" }
  },
  {
    prop: "error",
    label: "错误信息"
  },
  {
    prop: "times",
    label: "耗时 (单位: ms)"
  },
  {
    prop: "createTime",
    label: "日志记录时间"
  }
];

const proTable = ref<ProTableInstance>();

const getTableList = param => {
  return getJobLogPage(param);
};

const exportExcel = async () => {
  useDownload(exportJobLogExcel, proTable.value?.searchParam);
};
</script>
